-- Tags: long, no-tsan, no-parallel, no-random-settings
-- Tag: no-tsan -- too slow under TSan (~5-6min)
-- Tag: no-random-settings -- to avoid settings overlaps
-- Tag: no-parallel -- to reduce test time
--
-- Test for testing various read settings.

drop table if exists data_02051;

{# check each index_granularity_bytes #}
{% for index_granularity_bytes in [0, 10 * 1024 * 1024] %}
create table data_02051 (key Int, value String)
engine=MergeTree()
order by key
settings
    index_granularity_bytes={{ index_granularity_bytes }},
    /* to suppress "Table can't create parts with adaptive granularity, but settings ..." warning */
    min_bytes_for_wide_part=0
as select number, repeat(toString(number), 5) from numbers(1e6);

{# check each local_filesystem_read_method #}
{% for read_method in ['read', 'mmap', 'io_uring', 'pread_threadpool', 'pread_fake_async'] %}
{# check w/ O_DIRECT and w/o (min_bytes_to_use_direct_io) #}
{% for direct_io in [0, 1] %}
{# check local_filesystem_read_prefetch (just a smoke test) #}
{% for prefetch in [0, 1] %}
{# check read_priority (just a smoke test) #}
{% for priority  in [0, 1] %}
{# check alignment for O_DIRECT with various max_read_buffer_size #}
{% for buffer_size in [65505, 1048576] %}
select count(ignore(*)) from data_02051 settings
    min_bytes_to_use_direct_io={{ direct_io }},
    local_filesystem_read_method='{{ read_method }}',
    local_filesystem_read_prefetch={{ prefetch }},
    read_priority={{ priority }},
    max_read_buffer_size={{ buffer_size }}
;
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}

drop table data_02051;
{# index_granularity_bytes #}
{% endfor %}
